<?php
/**
 * 点赞管理
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/12 0012
 * Time: 下午 4:29
 */
namespace app\article\controller\like;
use app\article\model\Likes;
use app\article\validate\ValidateFun;
use app\article\validate\ValiLike;
use app\common\api\like\ILike;

class Like implements ILike{
    private $data =[];
    public function __construct(array $config=[]){
        $this->data = array_filter_full(array_merge($this->data,$config));
    }
    public function l_list()
    {
        // TODO: Implement l_list() method.
    }
    public function l_add(){
        $admin = session('admin_info');
        $default_data = [
            'user_id'   =>$admin['id'],
            'status'    =>1,
        ];
        $data = array_filter_full(array_merge($default_data,$this->data));
        unset($data['id']);
        #验证参数
        $vali = ValiLike::like_add();
        $validate = new ValidateFun($vali['rule'],$vali['message']);
        if (!$validate->check($data)){
            $err = $validate->getError();
            return ['code'=>$err,'msg'=>config("msg.$err")];
        }

        #添加
        $add = new Likes();
        $res = $add ->like_add($data);
        #返回
        if ($res>0){
            return ['code'=>200,'msg'=>config('msg.200')];
        }
        return ['code'=>10006,'msg'=>config('msg.10006')];

    }

    public function l_update()
    {
        // TODO: Implement l_update() method.
    }

}